package cn.doitedu.spark

import java.util

import org.apache.hadoop.hive.ql.udf.generic.GenericUDF
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory
import org.apache.hadoop.hive.serde2.objectinspector.{ObjectInspector, ObjectInspectorFactory, PrimitiveObjectInspector}

class AttrUDF extends GenericUDF{
  override def initialize(objectInspectors: Array[ObjectInspector]): ObjectInspector = {

    val names = new util.ArrayList[String]()
    names.add("event")
    names.add("ts")

    val fields = new util.ArrayList[ObjectInspector]()
    fields.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector)
    fields.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector)


    ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardStructObjectInspector(names,fields))
  }

  override def evaluate(deferredObjects: Array[GenericUDF.DeferredObject]): AnyRef = {
    val list = deferredObjects.toList
    val value = list(0).get()
    value
  }

  override def getDisplayString(strings: Array[String]): String = {

    return ""
  }
}
